﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections;
using Air_condition.GUI;
using ColdStorage.GUI;
using Com;

namespace Ecosystem
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainGui : Window
    {

        ucAirConditioning MainAir;
        public MainGui()
        {
           this.InitializeComponent();
        }

        public void GetAlt(string saltname)
        {
            MainAir.loadAlt(saltname);
        }

        public void GetRoom(string sroomname, string saltname)
        {
            MainAir.loadRoom(sroomname, saltname);
        }

        public void GetLocation(string sOutsideTemperaturee)
        {
            MainAir.SetOutsideTemperature(sOutsideTemperaturee);
        }

        public void AddRoom(string sroomname,string saltname, bool edit)
        {
            if (edit)
            {
                ((TreeViewItem)ucListInformation1.trvList.SelectedItem).Header = sroomname;
            }
            else
            {
                TreeViewItem tvRoom = new TreeViewItem();
                tvRoom.Header = sroomname;
                foreach (TreeViewItem t in ucListInformation1.tvAir.Items){
                    if(t.Header.ToString() == saltname){
                        t.Items.Add(tvRoom);
                    }
                }
            }
        }

        public void DeleteRoom(string sroomname, string saltname)
        {
            TreeViewItem troom = (TreeViewItem)ucListInformation1.trvList.SelectedItem;
            TreeViewItem talt = (TreeViewItem)troom.Parent;
            talt.Items.Remove(troom);
        }

        private void btnAir_Click(object sender, RoutedEventArgs e)
        {        
            try
            {
                ucListInformation1.MyRoom = new Mainform.ucListInformation.GetRoom(GetRoom);
                ucListInformation1.MyAlt = new Mainform.ucListInformation.GetAlt(GetAlt);
                ucListInformation1.MyLocation = new Mainform.ucListInformation.GetLocation(GetLocation);
                ucListInformation1.addAir();
                MainAir = new ucAirConditioning();
                MainAir.MyRoom = new ucAirConditioning.AddRoom(AddRoom);
                MainAir.DelRoom = new ucAirConditioning.DeleteRoom(DeleteRoom);
                this.pnlMainGui.Children.Clear();
                this.pnlMainGui.Children.Add(MainAir);
                ucListInformation1.Visibility = Visibility.Visible;
            }
            catch (Exception r) {
                MessageBox.Show(r.ToString());
            }

        }

        private void btnReport_Click(object sender, RoutedEventArgs e)
        {
            //Com.Report rp = new Com.Report();
            //rp.Show();
        }

        private void btnTemplate_Click(object sender, RoutedEventArgs e)
        {
            //Com.TemplateManager tem = new Com.TemplateManager();
            //tem.Show();
        }

        TreeViewItem tvCold = new TreeViewItem();
            
        private void btnCold_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                tvCold.Header = "Cold Storage";
                ucListInformation1.trvList.Items.Add(tvCold); 
                ucMainStorageCold MainColdStore = new ucMainStorageCold();
                this.pnlMainGui.Children.Clear();
                //this.pnlInformation.Children.Clear();
                ucListInformation1.Visibility = Visibility.Visible;
                this.pnlMainGui.Children.Add(MainColdStore);
                //this.pnlInformation.Children.Add(ucListTreeview);
            }
            catch (Exception r)
            {
                MessageBox.Show(r.ToString());
            }
            //this.ucListInformation1.addCold();
        }

        private void btnLibrary_Click(object sender, RoutedEventArgs e)
        {
            //Com.frmLibrary frmL = new Com.frmLibrary();
           // frmL.Show();
        }

        private void Ecosystem_Loaded(object sender, RoutedEventArgs e)
        {
            
        }

        private void btnAternative_Click(object sender, RoutedEventArgs e)
        {
            TreeViewItem tvAlt = new TreeViewItem();
            tvAlt.Header = "Alternative " + ucListInformation1.iAlternative;
            ucListInformation1.tvAir.Items.Add(tvAlt);
            ucListInformation1.iAlternative++;
            MainAir.addAlt(tvAlt.Header.ToString());
        }
    }
}
